import clr

import System
import Misuzilla.Crigate
import Misuzilla.Crigate.Scripting

from System                     import *
from System.Collections.Generic import *
from System.Diagnostics         import Trace

from Misuzilla.Crigate               import ConsoleHandler, Console, Context
from Misuzilla.Crigate.Configuration import IConfiguration, ConfigurationPropertyInfo
from Misuzilla.Crigate.Scripting     import DLRIntegrationHandler, DLRBasicConfiguration, DLRContextHelper

class TestContext(Context):
	def Initialize(self):
		#self.config = DLRBasicConfiguration(self.CurrentSession, "TestContext", Dictionary[String,String]({ "Hauhau": "設定項目の説明" }))
		self.config = DLRBasicConfiguration(self.CurrentSession, "TestContext", Array[ConfigurationPropertyInfo]([ConfigurationPropertyInfo("Maumau", "MAUMAU", System.Boolean, True, None), ConfigurationPropertyInfo("Hauhau", "設定項目の説明", System.String, "はうはう", None)]))
		pass

	def GetCommands(self):
		dict = Context.GetCommands(self)
		dict["Hauhau"] = "Say Hauhau!"
		return dict

	def OnUninitialize(self):
		pass

	def get_Configurations(self):
		return Array[IConfiguration]([ self.config ])

	def Maumau(self, args):
		pass

	# Implementation
	def hauhau(self, args):
		self.Console.NotifyMessage(("Hauhau: %s" % (args)))
		self.Console.NotifyMessage(("Hauhau(Config): %s" % (self.config.GetValue("Hauhau"))))

# コンソールチャンネルを追加する
console = Misuzilla.Crigate.Console()
console.Initialize(CurrentSession)
console.Attach("#TestConsole", DLRContextHelper.Wrap(CurrentSession, "Test", TestContext))

# 後片付け
CurrentSession.HandlerLoader.GetHandler[DLRIntegrationHandler]().BeforeUnload += lambda sender, e: console.Detach()
